import { userInfo } from "../../utils/api";
export default {
  namespaced: true,
  state: {
    info: {},
    cartTotal: 0,
  },
  mutations: {
    setInfo(state, { info, cartTotal } = {}) {
      state.info = info || {};
      state.cartTotal = cartTotal || 0;
    },
  },
  actions: {
    async getUserInfo(context) {
      // console.log(22);
      let res = await userInfo();
      if (res === false) return context.commit("setInfo");
      const info = res.data.userInfo;
      const cartTotal = res.data.cartTotal;
      context.commit("setInfo", { info, cartTotal });
    },
  },
};
